package som.simon.reactor;

import reactor.core.publisher.Mono;

public class IfEmptyMain {

    public static void main(String[] args) {
        // defaultIfEmpty 静态兜底数据
        getUserById().defaultIfEmpty(
                User.builder()
                        .id("00001")
                        .name("张三")
                        .desc("喜欢篮球")
                        .build()
        ).subscribe(user -> System.out.println("user = " + user));

        // 动态兜底数据
        getUserById().switchIfEmpty(
                Mono.just(User.builder()
                        .id("00001")
                        .name("张三")
                        .desc("喜欢篮球")
                        .build())
        ).subscribe(user -> System.out.println("user = " + user));

    }

    private static Mono<User> getUserById() {
        return Mono.empty();
    }

}
